package com.subang.function.controller;

import com.subang.common.annotation.Log;
import com.subang.common.core.controller.BaseController;
import com.subang.common.core.domain.AjaxResult;
import com.subang.common.core.page.TableDataInfo;
import com.subang.common.enums.BusinessType;
import com.subang.common.utils.poi.ExcelUtil;
import com.subang.function.domain.ShenlunReferenceAnswers;
import com.subang.function.service.IShenlunReferenceAnswersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 申论参考答案Controller
 * 
 * @author subei
 * @date 2025-02-26
 */
@RestController
@RequestMapping("/compare/answers")
public class ShenlunReferenceAnswersController extends BaseController
{
    @Autowired
    private IShenlunReferenceAnswersService shenlunReferenceAnswersService;

    /**
     * 查询申论参考答案列表
     */
    @PreAuthorize("@ss.hasPermi('compare:answers:list')")
    @GetMapping("/list")
    public TableDataInfo list(ShenlunReferenceAnswers shenlunReferenceAnswers)
    {
        startPage();
        List<ShenlunReferenceAnswers> list = shenlunReferenceAnswersService.selectShenlunReferenceAnswersList(shenlunReferenceAnswers);
        return getDataTable(list);
    }

    /**
     * 导出申论参考答案列表
     */
    @PreAuthorize("@ss.hasPermi('compare:answers:export')")
    @Log(title = "申论参考答案", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ShenlunReferenceAnswers shenlunReferenceAnswers)
    {
        List<ShenlunReferenceAnswers> list = shenlunReferenceAnswersService.selectShenlunReferenceAnswersList(shenlunReferenceAnswers);
        ExcelUtil<ShenlunReferenceAnswers> util = new ExcelUtil<ShenlunReferenceAnswers>(ShenlunReferenceAnswers.class);
        util.exportExcel(response, list, "申论参考答案数据");
    }

    /**
     * 获取申论参考答案详细信息
     */
    @PreAuthorize("@ss.hasPermi('compare:answers:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(shenlunReferenceAnswersService.selectShenlunReferenceAnswersById(id));
    }

    /**
     * 新增申论参考答案
     */
    @PreAuthorize("@ss.hasPermi('compare:answers:add')")
    @Log(title = "申论参考答案", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ShenlunReferenceAnswers shenlunReferenceAnswers)
    {
        return toAjax(shenlunReferenceAnswersService.insertShenlunReferenceAnswers(shenlunReferenceAnswers));
    }

    /**
     * 修改申论参考答案
     */
    @PreAuthorize("@ss.hasPermi('compare:answers:edit')")
    @Log(title = "申论参考答案", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ShenlunReferenceAnswers shenlunReferenceAnswers)
    {
        return toAjax(shenlunReferenceAnswersService.updateShenlunReferenceAnswers(shenlunReferenceAnswers));
    }

    /**
     * 删除申论参考答案
     */
    @PreAuthorize("@ss.hasPermi('compare:answers:remove')")
    @Log(title = "申论参考答案", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(shenlunReferenceAnswersService.deleteShenlunReferenceAnswersByIds(ids));
    }

}
